package com.rxtxdemo.rxtxdemo.applicationevent.task;

import com.rxtxdemo.rxtxdemo.applicationevent.publish.IComService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


//设备1状态管理
@Service
@Async
@Slf4j
public class Equipment1 {

    @Autowired
    private IComService userService;

    static Map<String, String> conMap = new ConcurrentHashMap<String, String>();
    static int a = 0;

    //测试控制设备
//    @Scheduled(fixedRate = 1000)
    public void testRegister() {
        log.info("测试控制设备 主线程id：[{}], 主线程名称 : [{}]" + Thread.currentThread().getId(), Thread.currentThread().getName());

//        //设备监控状态数据
//        //指令序列数据
//        if(conMap.size()==0){
//            conMap.put("one","true");
//            conMap.put("two", String.valueOf(RandomUtil.randomInt(1,30)));
//            conMap.put("three",String.valueOf(RandomUtil.randomInt(1,30)));
//        }
        if (a < 3) {
            userService.register(conMap);
            a++;
        } else {
            log.info(" 测试控制设备 结束");
        }

    }
}
